package com.matt.foundation.DO;

import com.matt.domain.LiveRoom;
import com.matt.foundation.utils.JsonValidateUtil;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/11/1
 * *******************************
 */
@Data
public class LiveRoomDO {
    private String id;
    private String name;
    private String url;
    private String HDUrl;
    private String thumbUrl;
    private String deviceSerial;
    private String ezUrl = "ezopen://open.ys7.com/%s/%s.live?mute=true";
    private String ezHDUrl = "ezopen://open.ys7.com/%s/%s.hd.live?mute=true";
    private Integer channelNo;
    private Integer livePlayWay;
    private Boolean follow =false;
    private String openTime;
    private String token;
    private String areaId;

    public static LiveRoomDO of(LiveRoom liveRoom){
        LiveRoomDO room = new LiveRoomDO();
        room.setId(liveRoom.getId());
        room.setName(liveRoom.getName());
        room.setUrl(liveRoom.getUrl());
        room.setHDUrl(liveRoom.getHDUrl());
        room.setThumbUrl(liveRoom.getThumbUrl());
        room.setDeviceSerial(liveRoom.getDeviceSerial());
        room.setChannelNo(liveRoom.getChannelNo());
        room.setOpenTime(liveRoom.getOpenTime());
        room.setLivePlayWay(liveRoom.getLiveWay());
        return room;
    }

    public static List<String> ofOpenTime(String openTime) throws Exception {
        if(StringUtils.isBlank(openTime))
            return null;
        ArrayList arrayList = JsonValidateUtil.objectMapper.readValue(openTime, ArrayList.class);
        return arrayList;
    }
}
